//
//  ZMRunTime.m
//  LoveBeen
//
//  Created by pg on 2017/8/10.
//  Copyright © 2017年 pg. All rights reserved.
//

#import "ZMRunTime.h"

@implementation ZMRunTime

    +(instancetype)shared{
        
        static ZMRunTime* instance;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            instance = [[self alloc ]init];
        });
        return  instance;
    }
    
    
    - (NSArray*)zm_getIvarList:(Class)class{
        unsigned int count = 0;
        Ivar * ivarList = class_copyIvarList(class, &count);
        NSMutableArray *mutableList = [NSMutableArray arrayWithCapacity:count];
        for (unsigned int i=0; i<count; i++) {
            NSMutableDictionary* dic = [NSMutableDictionary dictionaryWithCapacity:2];
            const char * ivarName = ivar_getName(ivarList[i]);
            const char *ivarType = ivar_getTypeEncoding(ivarList[i]);
            dic[@"type"] = [NSString stringWithUTF8String:ivarType];
            dic[@"ivarName"] = [NSString stringWithUTF8String:ivarName];
            [mutableList addObject:dic];
            
        }
        free(ivarList);
        return [NSArray arrayWithArray:mutableList];
        
    }
    
    
@end
